package com.o2o.cleaning.month.platform.ebusiness_plat.suning

import com.alibaba.fastjson.{JSON, JSONObject}
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2020/10/14 19:55
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object suning {
  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .appName("SparkTest")
//      .master("local[*]")
      .config("es.nodes", "192.168.1.29")
      .config("es.port", "9200")
      .config("es.net.http.auth.user", "elastic")
      .config("es.net.http.auth.pass", "changeme")
      .config("es.batch.write.retry.count", "10")
      .config("es.batch.write.retry.wait", "60")
      .config("cluster.name", "O2OElastic")
      .getOrCreate()
    val sc = spark.sparkContext
    val sqlcontext = spark.sqlContext

    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")

    val sourcePath = "s3a://dws-data/g_data/2020/shuang11/2019_yoy/meituan/"


    val resRDD: RDD[String] = spark.read.orc(sourcePath).toJSON.rdd.map(lines => {
      val nObject: JSONObject = JSON.parseObject(lines)

      val value1 = nObject.keySet().toArray()
      var string = "-1"
      var value12 = "-1"
      for (i <- value1) {
        value12 = nObject.get(i).toString
        nObject.put(i.toString, value12)
      }

//      val value: util.Iterator[String] = nObject.keySet().iterator()
//      if (value.hasNext) {
//        nObject.put(value.next(), nObject.getOrDefault(value.next(), "-1").toString)
//      }
      nObject.toString
    })
    spark.read.json(resRDD).write.orc("s3a://dws-data/g_data/2020/shuang11/2019_yoy/meituan_new/")

    spark.read.orc("s3a://dws-data/g_data/2020/shuang11/2019_yoy/meituan_new/").printSchema()

    /*val nObject: JSONObject = JSON.parseObject("")

    val value: util.Iterator[String] = nObject.keySet().iterator()

    if (value.hasNext){
      nObject.put(value.next(),nObject.getOrDefault(value.next(),"-1").toString)
    }



    val brand = new brand_join_res
    //    读取老品牌表路径
    //val brandTableOld = spark.read.json(brandTable_old)
    brand.brandJoinResult(spark.read.orc(sourcePath),"s3a://dws-data/g_data/2020/shuang11/2019_yoy/suning/",2020,9,"suning",spark)*/

  }

}
